<?php
namespace app\klingai\controller;
use think\Db;
use app\model\KlingaiRecord as RecordModel;

use Firebase\JWT\JWT;


class Videos extends Base
{   

    public function getPrice($action = 'undefined'){
        $price = 0;

        $method = request()->method();
        if ( strtolower($method) == 'post' ) {
            $data_string = file_get_contents('php://input');
            $params = json_decode($data_string,true);

            $price_data = [
                'controller'=>'videos',
                'action'=>$action
            ];
            $price_data['model_name'] = empty($params['model_name']) ? "kling-v1" : strtolower($params['model_name']);
            if ( !empty($params['mode']) ) {
                $price_data['mode'] = $params['mode'];
            }elseif( in_array($price_data['model_name'],['kling-v2-5-turbo']) ){
                $price_data['mode'] = 'pro';
            }elseif( in_array($price_data['model_name'],['kling-v2-master','kling-v2-1-master']) ){
                $price_data['mode'] = 'master';
            }else{
                $price_data['mode'] = 'std';
            }
            $price_data['duration'] = empty($params['duration']) ? "5" : $params['duration'];
            
            $price = Db::name('klingai_price')->where($price_data)->value('price');
            if (empty($price)) {
                exception('The product specification does not exist',5000);
            }
        }

        return $price;
    }

    // 文生视频
    public function text2video(){
        $price = $this->getPrice();

        $result = $this->commonAction($price);
        echo $result;
    }

    // 图生视频
    public function image2video(){
        $price = $this->getPrice();

        $result = $this->commonAction($price);
        echo $result;
    }

    // 多图参考生视频
    public function multi_image2video(){
        $price = $this->getPrice();

        $result = $this->commonAction($price);
        echo $result;
    }

    // 多模态视频编辑 - 初始化待编辑视频
    public function multi_elements_init_selection(){
        $price = 0;

        $result = $this->commonAction($price);
        echo $result;
    }

    // 多模态视频编辑 - 增加视频选区
    public function multi_elements_add_selection(){
        $price = 0;

        $result = $this->commonAction($price);
        echo $result;
    }

    // 多模态视频编辑 - 删减视频选区
    public function multi_elements_delete_selection(){
        $price = 0;

        $result = $this->commonAction($price);
        echo $result;
    }

    // 多模态视频编辑 - 清除视频选区
    public function multi_elements_clear_selection(){
        $price = 0;

        $result = $this->commonAction($price);
        echo $result;
    }

    // 多模态视频编辑 - 预览已选区视频
    public function multi_elements_preview_selection(){
        $price = 0;

        $result = $this->commonAction($price);
        echo $result;
    }

    // 多模态视频编辑
    public function multi_elements(){
        $price = $this->getPrice('multi-elements');

        $result = $this->commonAction($price);
        echo $result;
    }

    // 视频延长
    public function video_extend(){
        $price = -1; // 人工核算

        $result = $this->commonAction($price);
        echo $result;
    }

    // 数字人
    public function avatar_image2video(){
        $price = -1; // 人工核算

        $result = $this->commonAction($price);
        echo $result;
    }

    // 对口型
    public function advanced_lip_sync(){
        $price = -1; // 人工核算

        $result = $this->commonAction($price);
        echo $result;
    }

    // 对口型 - 人脸识别
    public function identify_face(){
        $price = -1; // 人工核算

        $result = $this->commonAction($price);
        echo $result;
    }

    // 视频特效
    public function effects(){
        $price = -1; // 人工核算

        $result = $this->commonAction($price);
        echo $result;
    }

    // 图像识别
    public function image_recognize(){
        $price = -1; // 人工核算

        $result = $this->commonAction($price);
        echo $result;
    }

}
